home *** CD-ROM | disk | FTP | other *** search
- #include "installDriver.h"
- /**********************************Comment*****************************************
- * Main looks for a "slot" in the UnitTable into which the driver can be placed. If
- * it finds a "slot" it calls the procedure changeDRVRSlot to install the driver
- * into that slot. Note that this code assumes that the resource file is open (the
- * changeDRVESlot routine needs to get at the DRVR): since the init and the DRVR
- * are in the same file this is safe.
- **********************************End Comment************************************/
- pascal main()
- {
- short tsSlot;
-
- if((tsSlot = lookForSlotInUnitTable()) != 0)
- changeDRVRSlot(tsSlot);
- }
-
- /**********************************Comment*****************************************
- * lookForSlotInUnitTable returns a short corresponding to a valid "slot" number. It'll
- range from 48 to UnitNTryCnt. If there are no slots available it returns 0. Essentially what
- we're doing here is starting at the END of the UnitTable, testing the value at each
- long-word location to see if it's nil. If it's nil, that means we can place our driver
- at that location, so we'll return the value of the "slot".
- **********************************End Comment************************************/
- short
- lookForSlotInUnitTable()
- {
- short slot;
- Ptr theBass;
- long *theVoidPtr;
- Boolean foundSlot;
-
- slot = *((short *)(UnitNtryCnt)) - 1;
- theBass = (Ptr) (*((long *) (UTableBase)));
-
- foundSlot = false;
-
- while(slot>48 && !foundSlot)
- {
- theVoidPtr = (long *)(theBass + (4L * slot));
-
- if(*theVoidPtr == 0L)
- foundSlot = true;
-
- slot -= 1;
- }
-
- slot += 1;
-
- if(!foundSlot)
- slot = 0;
-
- return slot;
- }
-
-
- /**********************************Comment*****************************************
- * changeDRVRSlot installs the driver into the slot passed in. Because we want to keep
- * our DRVR resource ID in the resource file the same as it ever was, we GetResInfo on
- * it, and then set it back later. But, before we set it back, we set the ID of the
- * DRVR resource equal to the slot found, and then call OpenDriver. OpenDriver uses the
- * resource ID of the DRVR resource to place it in the UnitTable -- pretty easy huh?
- * The only other tricky thing is we have to Detach the resource by calling DetachResource
- * so the resource doesn't go away when the resource file gets closed (the Resource
- * Manager is our friend). The resource file gets closed when the INIT stops executing.
- **********************************End Comment************************************/
- void
- changeDRVRSlot(short slot)
- {
- Handle theDRVR;
- short err, refNum;
- char *name, DRVRname[256];
- short DRVRid;
- ResType DRVRType;
-
- name = "\p.TimDriver";
-
- if(slot != 0) {
- theDRVR = GetNamedResource('DRVR', name);
- GetResInfo(theDRVR, &DRVRid, &DRVRType, &DRVRname);
- SetResInfo(theDRVR, slot, 0L);
-
- err = OpenDriver(name, &refNum);
- if(err == noErr)
- {
- /* detach the resources from the resource map */
- DetachResource(theDRVR);
-
- }
- /* Restores the previous resource attributes so they don't change
- * from startup to startup. We just want the in-memory copy to have
- * a different ID number -- not our resource in the file */
- theDRVR = GetNamedResource('DRVR', name);
- SetResInfo(theDRVR, DRVRid, nil);
- }
- }
-
-
- short
- rsrcID(short id, short DRVRRefNum)
- {
- return(0xC000 + (~DRVRRefNum << 5) + id);
- }
-